package com.ruibang.glass.purchase.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruibang.glass.purchase.domain.req.PurchaseArrivalReq;
import com.ruibang.glass.purchase.entity.PurchaseArrivalOrders;
import com.ruibang.glass.purchase.mapper.PurchaseArrivalProductMapper;
import com.ruibang.glass.purchase.service.PurchaseArrivalOrdersService;
import com.teaming.cloud.framework2.common.constant.CommonConstant;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 采购到货单
 *
 * @author mameng
 */
@Api(tags = "采购到货单")
@RestController
@RequestMapping("/api/glass/purchase/arrival")
public class PurchaseArrivalOrderController {

    @Autowired
    private PurchaseArrivalOrdersService purchaseArrivalOrdersService;

    @Autowired
    private PurchaseArrivalProductMapper purchaseArrivalProductMapper;


    @PostMapping("/list")
    @ApiOperation(value = "采购订单列表", response = ResultBody.class)
    public ResultBody queryAreas(@RequestBody PurchaseArrivalReq purchaseReportReq) {
        return ResultBody.success(purchaseArrivalOrdersService.getPage(purchaseReportReq));
    }

    @PostMapping("/add")
    @ApiOperation(value = "新增", response = ResultBody.class)
    public ResultBody addPurchaseArrivalOrders(@RequestBody PurchaseArrivalOrders purchaseArrivalOrders) {
        purchaseArrivalOrdersService.addPurchaseArrivalOrders(purchaseArrivalOrders);
        return ResultBody.success();
    }

    @PostMapping("/checkQuality")
    @ApiOperation(value = "质检", response = ResultBody.class)
    public ResultBody checkQuality(@RequestBody PurchaseArrivalOrders purchaseArrivalOrders) {
        purchaseArrivalOrdersService.checkQuality(purchaseArrivalOrders);
        return ResultBody.success();
    }

    @PostMapping("/updateCheckResult")
    @ApiOperation(value = "修改质检结果", response = ResultBody.class)
    public ResultBody updateCheckResult(@RequestBody PurchaseArrivalOrders purchaseArrivalOrders) {
        purchaseArrivalOrdersService.updateCheckResult(purchaseArrivalOrders);
        return ResultBody.success();
    }

    @GetMapping("/getCheckDetail/{id}")
    @ApiOperation(value = "查询修改质检详情", response = ResultBody.class)
    public ResultBody getCheckDetail(@PathVariable("id") String id) {
        return ResultBody.success(purchaseArrivalOrdersService.getCheckDetail(id));
    }

    @GetMapping("/getOne/{id}")
    @ApiOperation(value = "详情", response = ResultBody.class)
    public ResultBody getOne(@PathVariable("id") String id) {
        return ResultBody.success(purchaseArrivalOrdersService.getPurchaseArrivalOrders(id));
    }

    @GetMapping("/updateStatus/{number}")
    @ApiOperation(value = "修改入库状态为已入库", response = ResultBody.class)
    public ResultBody updateStatus(@PathVariable("number") String number) {
        purchaseArrivalOrdersService.update(Wrappers.<PurchaseArrivalOrders>lambdaUpdate()
                .set(PurchaseArrivalOrders::getStatus, CommonConstant.THREE_STR)
                .eq(PurchaseArrivalOrders::getPurchaseArrivalOrderNumber,number));
        return ResultBody.success();
    }

    @GetMapping("/delete/{id}")
    @ApiOperation(value = "删除", response = ResultBody.class)
    public ResultBody deleteOne(@PathVariable("id") String id) {
        purchaseArrivalOrdersService.deletePurchase(id);
        return ResultBody.success();
    }

    @GetMapping("/reBack/{id}")
    @ApiOperation(value = "获取次品退货详情", response = ResultBody.class)
    public ResultBody reBack(@PathVariable("id") String id) {
        return ResultBody.success(purchaseArrivalOrdersService.getReBackProduct(id));
    }


    @GetMapping("/getArrivalOrderNumber")
    @ApiOperation(value = "获取采购到货单号", response = ResultBody.class)
    public ResultBody getArrivalOrderNumber() {
        return ResultBody.success(purchaseArrivalOrdersService.getArrivalOrderNumber());
    }


    @GetMapping("/getMaterialInNumber")
    @ApiOperation(value = "获取入库单号", response = ResultBody.class)
    public ResultBody getMaterialInNumber() {
        return ResultBody.success(purchaseArrivalOrdersService.getMaterialInNumber());
    }


    @GetMapping("/getArrivalNumberList")
    @ApiOperation(value = "获取采购到货单集合", response = ResultBody.class)
    public ResultBody getArrivalNumberList() {
        return ResultBody.success(purchaseArrivalOrdersService.getArrivalNumberList());
    }

    @GetMapping("/getBatchNumberList/{id}")
    @ApiOperation(value = "获取批次号下拉", response = ResultBody.class)
    public ResultBody getBatchNumber(@PathVariable("id") String id) {
        return ResultBody.success(purchaseArrivalOrdersService.getBatchNumber(id));
    }

    @GetMapping("/getProductById/{id}")
    @ApiOperation(value = "获取原材料物料详情", response = ResultBody.class)
    public ResultBody getProductById(@PathVariable("id") String id) {
        return ResultBody.success(purchaseArrivalProductMapper.selectById(id));
    }


    @GetMapping("/getOrderNumberList")
    @ApiOperation(value = "获取质检已到库的订单号", response = ResultBody.class)
    public ResultBody getBatchNumber() {
        return ResultBody.success(purchaseArrivalOrdersService.getOrderNumberList());
    }

    @GetMapping("/getSuppilerListByNumber/{number}")
    @ApiOperation(value = "获取供应商", response = ResultBody.class)
    public ResultBody getSuppilerListByNumber(@PathVariable("number")String number) {
        return ResultBody.success(purchaseArrivalOrdersService.getSuppilerListByNumber(number));
    }

    @GetMapping("/getOrderItemListById/{number}")
    @ApiOperation(value = "更具订单号获取下拉物品", response = ResultBody.class)
    public ResultBody getOrderItemListById(@PathVariable("number") String number) {
        return ResultBody.success(purchaseArrivalOrdersService.getOrderItemListById(number));
    }

    @PostMapping("/getProductInfoByNumberAndCode")
    @ApiOperation(value = "更具单号和物料code获取到货数量", response = ResultBody.class)
    public ResultBody getProductInfoByNumberAndCode(@RequestBody PurchaseArrivalOrders purchaseArrivalOrders) {
        return ResultBody.success(purchaseArrivalOrdersService.getProductInfoByNumberAndCode(purchaseArrivalOrders));
    }


    @PostMapping("/getBrocadeByNumberAndCode")
    @ApiOperation(value = "更具单号和物料code获取到货数量", response = ResultBody.class)
    public ResultBody getBrocadeByNumberAndCode(@RequestBody PurchaseArrivalOrders purchaseArrivalOrders) {
        return ResultBody.success(purchaseArrivalOrdersService.getBrocadeByNumberAndCode(purchaseArrivalOrders));
    }

    @PostMapping("/getBatchNumberByNumberAndCode")
    @ApiOperation(value = "更具单号和物料code获取到货数量", response = ResultBody.class)
    public ResultBody getBatchNumberByNumberAndCode(@RequestBody PurchaseArrivalOrders purchaseArrivalOrders) {
        return ResultBody.success(purchaseArrivalOrdersService.getBatchNumberByNumberAndCode(purchaseArrivalOrders));
    }



}
